package site.xuxingcan.Util;

import site.xuxingcan.Type.MahjongType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * Created by xuxingcan on 16-7-15.
 */
public class ActionUtil {
    /**
     * 0或1.无 2.碰 3.杠和碰
     *
     * @param mahjongTypeArrayList
     * @param type
     * @return
     */
    public static int checkPengPaiOrGangPai(ArrayList<MahjongType> mahjongTypeArrayList, MahjongType type) {
        int count = 0;
        for (MahjongType mahjongType : mahjongTypeArrayList) {
            if (mahjongType.isSame(type)) {
                count++;
            }
        }
        return count;
    }

    public static int isWin() {
        //先判断是否胡，后面再计算番
        return -1;
    }

    public static boolean checkQiDui(ArrayList<MahjongType> mahjongTypeArrayList) {
        if (mahjongTypeArrayList.size() != 14) {
            return false;
        }
        Comparator<MahjongType> comparator = new Comparator<MahjongType>() {

            @Override
            public int compare(MahjongType o1, MahjongType o2) {
                if (o1.type == o2.type) {
                    return o1.number - o2.number;
                } else {
                    return o1.type - o2.type;
                }
            }
        };
        Collections.sort(mahjongTypeArrayList, comparator);
        for (int i = 0; i < mahjongTypeArrayList.size(); i += 2) {
            if (!mahjongTypeArrayList.get(i).isSame(mahjongTypeArrayList.get(i + 1))) {
                return false;
            }
        }
        return true;
    }

    public static boolean checkHu(ArrayList<MahjongType> mahjongTypeArrayList) {
        Comparator<MahjongType> comparator = new Comparator<MahjongType>() {

            @Override
            public int compare(MahjongType o1, MahjongType o2) {
                if (o1.type == o2.type) {
                    return o1.number - o2.number;
                } else {
                    return o1.type - o2.type;
                }
            }
        };
        Collections.sort(mahjongTypeArrayList, comparator);

        return true;
    }
}
